import {httpClient} from '@/utils/request/request-client';
import {LoginParams, LoginResult, RefreshTokenResult, UserInfoResult} from "@/api/model/core";

enum Api {
  Basic = "/auth",

  Login = Basic + '/login',
  Refresh = Basic + '/refresh',
  Logout = Basic + '/logout',
  Codes = Basic + '/codes',
  UserInfo = Basic + '/getInfo',
}

/**
 * 登录
 */
export async function loginApi(data: LoginParams) {
  return httpClient.post<LoginResult>(Api.Login, data);
}

/**
 * 刷新accessToken
 */
export async function refreshTokenApi() {
  return httpClient.post<RefreshTokenResult>(Api.Refresh, {
    withCredentials: true,
  });
}

/**
 * 退出登录
 */
export async function logoutApi() {
  return httpClient.post(Api.Logout, {
    withCredentials: true,
  });
}

/**
 * 获取用户权限码
 */
export async function getAccessCodesApi() {
  return httpClient.get<string[]>(Api.Codes);
}

/**
 * 获取用户信息
 */
export async function getUserInfoApi() {
  return httpClient.get<UserInfoResult>(Api.UserInfo);
}
